<layout name="layout" />
<div class="pageheader notab">
	<h1 class="pagetitle" id="campaign_title">我思故我牛</h1>
	<ul class="breadcrumbs breadcrumbs2"  >
		<li><a href="/algorithm">我思故我牛</a><span class="divider">&#187;</span></li>
		<li><a href="/algorithm/condition">我的思路</a><span class="divider">&#187;</span></li>
		<li>编辑</li>
	</ul>
</div>
<div clear="all"></div>
<style>
	td a {
		margin-left: 5px;
	}
	.condition-input {
		width: 50px;
		display: inline-block;
	}
	#popup_container {
		top: 10% !important;
	}
	.s-model span{
		width: 100px;
		display: inline-block;
		margin-top: 5px;
	}
	.indexUnit {
		margin-left: 5px;
	}
	.k_box {
		margin-top:-20px;border-bottom:1px solid #DDDDDD;padding:10px 0px;
	}
	input {
		vertical-align: middle !important; 
	}
</style>
<php>
	$date = array(
		1=>'昨天',
		3=>'最近三天',
		7=>'最近一周',
		15=>'最近半个月',
		30=>'最近一个月',
	);
	$indexName = array(
		'impressions' => '展现量',
		'click' => '点击量',
		'ctr' => '点击率',
		'cpc' => '平均点击花费',
		'cvr' => '点击转化率',
		'avgpos' => '宝贝排名',
		'qscore' => '质量得分',
		'cost' => '总花费',
		'sales' => '总成交',
		'roi' => '投入产出比',
		'fav_count' => '收藏数',
		'fav_count_rate' => '收藏率',
		'cart_total' => '购物车数',
		'cart_total_rate' => '购物车率',
	);
	$conditions = array(
		1=>'>',
		2=>'=',
		3=>'<',
		4=>'<=',
		5=>'>='
	);
</php>
<div id="contentwrapper" class="contentwrapper">
	<div id="maincontent">
		<div class="widget" id="index-add-table" style="width:800px;">
			<table class="metrotable datatable">
				<thead>
					<tr>
						<th>维度</th>
						<th>条件</th>
						<th>比例</th>
						<th>数据维度</th>
						<th>参考数值</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
					<foreach name="thinkingInfo['content']['indexs']" item="vo" key="ky">
					<tr class="index-for-con">
						<td class="index-td">
							<select name="index_{$thinkingInfo['id']}{$ky}" class="index-name">
								<option value=""></option>
								<foreach name="indexName" item="index" key="index_ky">
								<option value="{$index_ky}" <if condition="$index_ky == $vo['intdex_name']">selected</if>>{$index}</option>
								</foreach>
							</select>
						</td>
						<td>
							<select name="conditions_{$thinkingInfo['id']}{$ky}" class="conditions">
								<foreach name="conditions" item="condition" key="condition_ky">
								<option value="{$condition_ky}" <if condition="$condition == $vo['intdex_condition']">selected</if>>{$condition}</option>
								</foreach>
							</select>
						</td>
						<td>
							<input type="text" class="condition-input click-min" name="value" class="value" value="{$vo['intdex_value']}">&nbsp;&#37;
						</td>
						<td>
							<!--<span><input type="radio" name="depth_{$thinkingInfo['id']}{$ky}" class="depth" value="1" disabled>账户</span>
							<span style="margin-left:10px;"><input type="radio" name="depth_{$thinkingInfo['id']}{$ky}" class="depth" value="2" disabled>计划</span>
							<span style="margin-left:10px;"><input type="radio" name="depth_{$thinkingInfo['id']}{$ky}" class="depth" value="3" disabled>宝贝</span>-->
							<if condition="$thinkingInfo['type'] == 3">
							<span style="margin-left:10px;"><input type="radio" name="depth_{$thinkingInfo['id']}{$ky}" class="depth" value="3" checked>宝贝</span>
							<elseif condition="$thinkingInfo['type'] == 4"/>
							<span style="margin-left:10px;"><input type="radio" name="depth_{$thinkingInfo['id']}{$ky}" class="depth" value="4" checked>自选</span>
							</if>
						</td>
						<td>
							<span><input type="radio" name="srouceType_{$thinkingInfo['id']}{$ky}" class="srouceType" value="1" <if condition="1 == $vo['intdex_srouceType']">checked</if>>均值</span>
							<span style="margin-left:10px;"><input type="radio" name="srouceType_{$thinkingInfo['id']}{$ky}" class="srouceType" value="2" <if condition="2 == $vo['intdex_srouceType']">checked</if>>最大值</span>
							<span style="margin-left:10px;"><input type="radio" name="srouceType_{$thinkingInfo['id']}{$ky}" class="srouceType" value="3" <if condition="3 == $vo['intdex_srouceType']">checked</if>>自定义<input type="text" data-validate="true" class="condition-input click-min srouceValue" style="margin-left:5px;" name="srouceValue" <if condition="3 == $vo['intdex_srouceType']">value="{$vo['intdex_srouceValue']}"</if>><span class="indexUnit"><php>if(in_array($vo['intdex_name'], array('ctr','cvr','fav_count_rate','cart_total_rate'))) {echo '%';} else if(in_array($vo['intdex_name'], array('cpc','cost','sales'))) {echo "元";}</php></span></span>
						</td>
						<td>
							<if condition="$ky == 0">
							<button class="stdbtn add-index" type="button">增加指标 (并且)</button>
							<else/>
							<button class="stdbtn delete-index">删除指标</button>
							</if>
						</td>
					</tr>
					</foreach>
				</tbody>
			</table>
			<div class="k_box" style="margin-bottom:10px;">
				<h4>参考数值时效</h4>
				<div class="s-model">
					<span>
						<select name="effectivedate">
							<foreach name="date" item="vo" key="ky">
							<option value="{$ky}" <if condition="$ky == $thinkingInfo['content']['date']">selected</if>>{$vo}</option>
							</foreach>
						</select>
					</span>
				</div>
			</div>
			<div class="k_box priceModel" style="margin-top:-10px;">
				<input type="hidden" name="priceModel" value="0"> 
				<h4>调价模式</h4>
				<span style="width:auto;">开启调价模式<input type="checkbox" style="vertical-align: middle; " class="priceModelStart"></span>
				<div class="s-model" id="s-model-1">
					<span>按百分比调价</span>
					<span>
						<input type="radio" name="addbyfix" class="addbyfix" value="1" >降价
						<input type="radio" name="addbyfix" class="addbyfix" value="2">提价
					</span>
					<span style="width:110px;">
						<input type="text" class="condition-input click-min addbyfixVal" name="addbyfixVal">&nbsp;&#37; 原价，
					</span>
					<span style="width:200px;">
						<span id="s-model-value-set-addbyfixVal" style="width:auto;">最高不得多于</span><input type="text" class="condition-input click-min addbyfixValMax" name="addbyfixValMax" style="margin-left:5px;">&nbsp;元
					</span>
				</div>
				<div class="s-model" id="s-model-2">
					<span>原基础上调价</span>
					<span>
						<input type="radio" name="addpricewithratio" class="addpricewithratio" value="1">降价
						<input type="radio" name="addpricewithratio" class="addpricewithratio" value="2">提价
					</span>
					<span style="width:auto;">
						<input type="text" class="condition-input click-min addpricewithratioVal" name="addpricewithratioVal">&nbsp;元，
					</span>
					<span style="width:200px;">
						<span id="s-model-value-set-addpricewithratioVal" style="width:auto;">最高不得多于</span><input type="text" class="condition-input click-min addpricewithratioValMax" name="addpricewithratioValMax" style="margin-left:5px;">&nbsp;元
					</span>
				</div>
				<div class="s-model" id="s-model-3">
					<span>统一出价</span>
					<span>
						<input type="text" class="condition-input click-min setbyfixVal" name="setbyfixVal">&nbsp;元
					</span>
				</div>
			</div>
			<div class="k_box matchscope" style="margin-top:0px;">
				<h4>匹配模式</h4>
				<if condition="$thinkingInfo['content']['matchscopeModel']['status'] == 1">
				<div class="s-model-matchscopeModel">
					<span style="width:auto;">开启匹配模式修改<input type="checkbox" style="vertical-align: middle; " class="matchscopeModel" checked></span>
					<span style="width:200px;margin-left:10px;">
						<input type="radio" name="matchscope" value="1" <if condition="$thinkingInfo['content']['matchscopeModel']['value'] == 1">checked</if> class="fuzzy">广泛匹配
						<input type="radio" name="matchscope" value="2" <if condition="$thinkingInfo['content']['matchscopeModel']['value'] == 2">checked</if> class="center">中心词
						<input type="radio" name="matchscope" value="3" <if condition="$thinkingInfo['content']['matchscopeModel']['value'] == 3">checked</if> class="fix">精确匹配
					</span>
				</div>
				<else/>
				<div class="s-model-matchscopeModel">
					<span style="width:auto;">开启匹配模式修改<input type="checkbox" style="vertical-align: middle; " class="matchscopeModel"></span>
					<span style="width:200px;margin-left:10px;">
						<input type="radio" name="matchscope" value="1" disabled="true" class="fuzzy">广泛匹配
						<input type="radio" name="matchscope" value="2" disabled="true" class="center">中心词
						<input type="radio" name="matchscope" value="3" disabled="true" class="fix">精确匹配
					</span>
				</div>
				</if>
			</div>
			<div class="k_box matchscope" style="margin-top:0px;">
				<h4>删除</h4>
				<div class="s-model-delete">
					<span style="width:auto;">删除符合条件的关键词<input type="checkbox" id="delete" name="delete" style="vertical-align: middle;"></span>
				</div>
			</div>

			<div class="k_box matchscope" style="margin-top:0px;margin-bottom:10px;">
				<h4>思路名称</h4>
				<div class="s-model-title">
					<input type="text" class="thinkingName" value="{$thinkingInfo['title']}" name="thinkingName">
				</div>
			</div>

			<div stype="margin-top:10px;">
				<input type="hidden" name="refUrl" value="{$refUrl}">
				<button class="stdbtn save-btn">保存思路</button>
				<span class="loading" style="display:none;">正在跳转……</span>
				<button class="stdbtn return-btn" style="margin-left:10px;">返回</button>
			</div>
		</div>
	</div>
</div>
<script id="con_box-tr" type="text/html">
	<tr class="index-for-con">
		<td class="index-td">
			<select name="index_[%n%]" class="index-name">
				<option value=""></option>
				<option value="impressions">展现量</option>
				<option value="click">点击量</option>
				<option value="ctr">点击率</option>
				<option value="cpc">平均点击花费</option>
				<option value="cvr">点击转化率</option>
				<option value="avgpos">宝贝排名</option>
				<option value="qscore">质量得分</option>
				<option value="cost">总花费</option>
				<option value="sales">总成交</option>
				<option value="roi">投入产出比</option>
				<option value="fav_count">收藏数</option>
				<option value="fav_count_rate">收藏率</option>
				<option value="cart_total">购物车数</option>
				<option value="cart_total_rate">购物车率</option>
			</select>
		</td>
		<td>
			<select name="conditions_[%n%]" class="conditions">
				<option value="1">&gt;</option>
				<option value="2">&#61;</option>
				<option value="3">&lt;</option>
				<option value="4">&lt;&#61;</option>
				<option value="5">&gt;&#61;</option>
			</select>
		</td>
		<td>
			<input type="text" class="condition-input click-min" name="value" class="value" value="100">&nbsp;&#37;
		</td>
		<td>
			<!--<span><input type="radio" name="depth_[%n%]" class="depth" value="1" disabled>账户</span>
			<span style="margin-left:10px;"><input type="radio" name="depth_[%n%]" class="depth" value="2" disable>计划</span>
			<span style="margin-left:10px;"><input type="radio" name="depth_[%n%]" class="depth" value="3" disable>宝贝</span>-->
			<span style="margin-left:10px;"><input type="radio" name="depth_[%n%]" class="depth" value="4" checked>自选</span>
		</td>
		<td>
			<span><input type="radio" name="srouceType_[%n%]" class="srouceType" value="1">均值</span>
			<span style="margin-left:10px;"><input type="radio" name="srouceType_[%n%]" class="srouceType" value="2">最大值</span>
			<span style="margin-left:10px;"><input type="radio" name="srouceType_[%n%]" class="srouceType" value="3">自定义<input type="text" data-validate="true" class="condition-input click-min" style="margin-left:5px;ime-mode:disabled;" name="srouceValue" class="srouceValue"></span>
		</td>
		<td>
			<button class="stdbtn delete-index">删除指标</button>
		</td>
	</tr>
</script>
<script type="text/javascript" src="/Js/dist/mlkr.js"></script>
<script>
	//删除
	(function(){
		EventUtil.addHandler(document, 'click', function(event) {  //监听onclick事件
		    if (document.activeElement.id == 'delete'){  //判断当前element id 是不是 'delete'
		    	var list1 = document.getElementsByClassName('k_box priceModel')[0].getElementsByTagName("input");
		    	var list2 = document.getElementsByClassName('k_box matchscope')[0].getElementsByTagName("input");
		    	if (document.activeElement.checked) {  //判断是否选中		    		
		    		elementsDisabled(list1);
		    		elementsDisabled(list2);
		    	}else{	    		
	    			elementsAbled(list1);
	    			elementsAbled(list2);
		    	}
		    }
		});
	})();

	//使elements失效
	function elementsDisabled (list) {
		for (var i = list.length - 1; i >= 0; i--) {
		    list[i].setAttribute('disabled','disabled');
		    list[i].checked = false;
		}
	}

	//恢复elements
	function elementsAbled(list) {
		for (var i = list.length - 1; i >= 0; i--) {
		    list[i].removeAttribute('disabled');
		}
	}

	(function($) {
		var editId = {$thinkingInfo.id};
		window.onload = old_data;
		function old_data () {
			var old_priceModel = {
				status : {$thinkingInfo['content']['priceModel']['status']},
				priceType : '{$thinkingInfo['content']['priceModel']['priceType']}',
				priceValue : '{$thinkingInfo['content']['priceModel']['priceValue']}',
				optionType : <php>echo isset($thinkingInfo['content']['priceModel']['optionType']) ? $thinkingInfo['content']['priceModel']['optionType'] : 0</php>,
				priceExtreme : <php>echo isset($thinkingInfo['content']['priceModel']['priceExtreme']) ? $thinkingInfo['content']['priceModel']['priceExtreme'] : 0</php>
			},
			delete_signal = <php>echo isset($thinkingInfo['content']['delete']['status']) ? (int)$thinkingInfo['content']['delete']['status'] : 0</php>;
			if(delete_signal == 1) {
				$('.priceModelStart').attr('disabled', true);
				$('.matchscopeModel').attr('disabled', true);
				$('.priceModel').find('[name=priceModel]').val(0);
				$('.priceModelStart').attr('checked', false);
				$('.priceModel').find('.s-model input').attr('disabled', true);
				$("#delete").click();
			} else if(old_priceModel.status == 1) {
				$('.priceModelStart').attr('checked', true);
				switch(parseInt(old_priceModel.priceType))
				{
					case 1:
						$('.priceModel').find('[name=priceModel]').val(1);
						var method = $('#s-model-1').find('[name=addbyfix]');
						$.each(method, function(i, x) {
							if($(x).val() == old_priceModel.optionType)
								$(x).click();
						});
						$('.addbyfixVal').val(old_priceModel.priceValue);
						$('.addbyfixValMax').val(old_priceModel.priceExtreme);
						break;
					case 2:
						$('.priceModel').find('[name=priceModel]').val(2);
						var method = $('#s-model-2').find('[name=addpricewithratio]');
						$.each(method, function(i, x) {
							if($(x).val() == old_priceModel.optionType)
								$(x).click();
						});
						$('.addpricewithratioVal').val(old_priceModel.priceValue);
						$('.addpricewithratioValMax').val(old_priceModel.priceExtreme);
						break;
					case 3:
						$('.priceModel').find('[name=priceModel]').val(3);
						$('.setbyfixVal').val(old_priceModel.priceValue);
						$('.addbyfixVal, .addbyfixValMax, .addpricewithratioVal, .addpricewithratioValMax').attr('disabled', true);
						break;
					default:
						$('.priceModel').find('[name=priceModel]').val(0);
				}
			} else {
				$('.priceModel').find('[name=priceModel]').val(0);
				$('.priceModelStart').attr('checked', false);
				$('.priceModel').find('.s-model input').attr('disabled', true);
			}
		}

		var addIndex = {
				index: '请选择维度',
				conditions: '请选择条件',
				value: '请输入比例',
				depth: '请选择数据维度',
				srouceType: '请选择参考数值'
			},
			indexUnit = {
				ctr: '%',
				cpc: '元',
				cvr: '%',
				cost: '元',
				sales: '元',
				fav_count_rate : '%',
				cart_total_rate : '%'
			};

		var _index = {};

		var option = {
			name: '',
			indexs: {},
			date: 1,
			priceModel: {
				status : 1,
				priceType: null,
				optionType: null,
				priceValue: null,
				priceExtreme: null
			},
			matchscopeModel: {
				status: 0,
				value: null
			},
			adgroup_id: 0,
			campaign_id: 0,
			delete_signal: 0
		}

		// $('.t_list_o').click(function() {
		// 	// var $this = $(this);
		// 	alert('aaaa');
		// 	// if($this.data('id')) {
		// 	// 	var r = confirm("确认要操作")
		// 	// 	if(r) {
		// 	// 		wt.post('/algorithm/execute', {thinkingId: $this.data('id')}, function(r) {
		// 	// 			var o = $.parseJSON(r);
		// 	// 			alert('共处理了'+o.data.length+'个关键词');
		// 	// 			location.reload();
		// 	// 		})
		// 	// 	}
		// 	// }
		// });
		
		// 保存思路
		$(document).on('click', ".save-btn", function() {

			var $this = $(this),
				_break = false,
				v = 0,
				w = 0,
				q = null,
				I = $(".index-for-con"),
				priceModelDiv = $('.priceModel'),
				matchscopeModel = $('.matchscopeModel');

			I.each(function(i, x) {
				// 检测指标各项值
				if (!checkIndex(x)) {
					option.indexs = {};
					_break = true;
					return false;
				}
				q = 'index_' + i + '_v';
				v = $(x).find('[name^="srouceType"]:checked').val();
				w = v == 3 ? $(x).find('[name^="srouceValue"]').val() : w;
				option.indexs[q] = {
					intdex_name: $(x).find('.index-name').val(),
					intdex_condition: $(x).find('.conditions').val(),
					intdex_value: $(x).find('[name=value]').val(),
					intdex_depth: $(x).find('[name^="depth"]:checked').val(),
					intdex_srouceType: v,
					intdex_srouceValue: w
				};
			});

			if (_break) {
				return false;
			}



			// 调价模式检测
			if ($('.priceModelStart').is(':checked')) {
				var priceModel = priceModelDiv.find('[name=priceModel]').val();
				if (!priceModelDiv.find('[name=addbyfix]:checked').val() && !priceModelDiv.find('[name=addpricewithratio]:checked').val() && !priceModelDiv.find('[name=setbyfixVal]').val()) {
					alert("请选择调价模式");
					return false;
				}

				if (priceModelDiv.find('[name=priceModel]').val() == 1) {
					if (priceModelDiv.find('[name=addbyfixVal]').val() == '' || priceModelDiv.find('[name=addbyfixValMax]').val() == '') {
						alert("请填写调价百分比及最值");
						return false;
					}
					option.priceModel = {
						status : 1,
						priceType: 1,
						optionType: priceModelDiv.find('[name=addbyfix]:checked').val(),
						priceValue: priceModelDiv.find('[name=addbyfixVal]').val(),
						priceExtreme: priceModelDiv.find('[name=addbyfixValMax]').val()
					}
				} else if (priceModelDiv.find('[name=priceModel]').val() == 2) {
					if (priceModelDiv.find('[name^="addpricewithratioVal"]').val() == '' || priceModelDiv.find('[name=addpricewithratioValMax]').val() == '') {
						alert("请填写调价数值及最值");
						return false;
					}
					option.priceModel = {
						status : 1,
						priceType: 2,
						optionType: priceModelDiv.find('[name=addpricewithratio]:checked').val(),
						priceValue: priceModelDiv.find('[name=addpricewithratioVal]').val(),
						priceExtreme: priceModelDiv.find('[name=addpricewithratioValMax]').val()
					}
				} else {
					option.priceModel = {
						status : 1,
						priceType: 3,
						priceValue: priceModelDiv.find('[name=setbyfixVal]').val()
					}
				}
			} else {
				option.priceModel.status = 0;
			}

			if (matchscopeModel.is(':checked')) {
				if (!matchscopeModel.parents('.matchscope').find('[name=matchscope]:checked').val()) {
					alert("请选择匹配模式");
					return false;
				}

				option.matchscopeModel = {
					status: 1,
					value: matchscopeModel.parents('.matchscope').find('[name=matchscope]:checked').val()
				}
			} else {
				option.matchscopeModel.status = 0;
			}



			option.date = $this.parents('#index-add-table').find('[name=effectivedate]').val();

			option.name = $this.parents('#index-add-table').find('[name=thinkingName]').val();

			option.delete_signal = $('#delete').is(':checked') ? 1 : 0;

			if(!option.name) {
				alert("请填写思路名称");
				return false;
			}

			option.editOption = true;
			option.editId = editId;
			$this.attr('disabled', true);
			$this.text('正在提交数据……');
			wt.post('/algorithm/save', option, function(r) {
				$this.text('保存思路成功');
				$this.next().show();
				setTimeout(function() {
					window.location.href = $('[name=refUrl]').val();
				}, 2000);
			});
		});
		
		// 返回
		$('.return-btn').click(function() {
			window.location.href = $('[name=refUrl]').val();
		});

		// 添加条件
		$(document).on("click", ".add-index", function() {
			// if($(".index-for-con").length >= 10) {
			// 	alert("最多只能增加10个指标");
			// 	return;
			// }
			// var u = '';
			var time = (new Date()).valueOf();
			var new_tr = template.render('con_box-tr');
			new_tr = new_tr.replace(/\[\%n\%\]/g, time);
			$("#index-add-table").find('tbody').append(new_tr);
			// var current_tr = $(".index-for-con");
			// var current_tr_count = current_tr.length -1;

			// var ss = current_tr[current_tr_count];
			// current_tr.each(function(i, x) {
			// 	if(i < current_tr_count) {
			// 		u = $(x).find('.index-name').val();
			// 		// t = $(new_tr).find("option[value="+u+"]").remove().html();
			// 		if(u != '')
			// 			$(ss).find("td:first option[value="+u+"]").attr('disabled', true);
			// 	}
			// });
			// alert(t.html());
			// 

		});

		// 删除条件
		$(document).on("click", ".delete-index", function() {
			$(this).parents('tr').remove();
		});

		function checkIndex(obj) {
			var o = $(obj),
				tmp = null;
			for (var key in addIndex) {
				if (key == 'depth' || key == 'srouceType') {
					tmp = o.find('[name^="' + key + '"]:checked');
				} else {
					tmp = o.find('[name^="' + key + '"]');
				}
				if (!tmp.val()) {
					alert(addIndex[key]);
					return false;
				}
				if (key == 'srouceType' && tmp.val() == 3 && o.find('.srouceValue').val() == '') {
					alert('请填写自定义参考数值');
					return false;
				}
				// if(key == 'value') {
				// 	checkPercent(tmp);
				// }
			}
			return true;
		}

		function checkPercent(obj) {
			var str = obj.val(),
				Reg = new RegExp(/^([1-9]{1}[0-9]{0,1}|0)(\.\d{1,2}){0,1}$/);
			if (!Reg.test(str)) {
				alert("格式错误，有效格式如：88.88%(整数最多两位，小数位最多为两位)");
				obj.value = "";
				obj.focus();
				return false;
			}
			return true;
		}

		$(document).on('click', '[name^="srouceType"]', function() {
			var $this = $(this),
				t = $this.parents('tr').find('.index-name').val();
			if ($this.val() == 3 && indexUnit.hasOwnProperty(t)) {
				$this.parents('tr').find('.indexUnit').html(indexUnit[t]);
			} else {
				$this.parents('tr').find('.indexUnit').html('');
				$this.parents('tr').find('.srouceValue').val('');
			}
		});

		// 输入框验证
		$(document).on('keyup', '[data-validate=true]', function() {
			var $this = $(this),
				t = $this.val();
			//先把非数字的都替换掉，除了数字和.
			t = $this.val(t.replace(/[^\d.]/g, "")).val();
			//必须保证第一个为数字而不是.
			t = $this.val(t.replace(/^\./g, "")).val();
			//保证只有出现一个.而没有多个.
			t = $this.val(t.replace(/\.{2,}/g, ".")).val();
			//保证.只出现一次，而不能出现两次以上
			$this.val(t.replace(".", "$#$").replace(/\./g, "").replace("$#$", "."));
		});

		// 调价模式 -按百分比调价
		$(document).on('click', '.addbyfix', function() {
			var $this = $(this);
			var this_p = $this.parents('.k_box');
			this_p.find('[name=addpricewithratio]').attr('checked', false);
			this_p.find('[name^="addpricewithratioVal"]').val('').attr('disabled', true);
			this_p.find('[name^="setbyfixVal"]').val('');

			this_p.find('[name^="addbyfixVal"]').attr('disabled', false);
			this_p.find('[name=addbyfixVal]').focus();
			this_p.find('[name=priceModel]').val(1);
			if($this.val() == 1) {
				$('#s-model-value-set-addbyfixVal').text('最低不得少于');
			} else {
				$('#s-model-value-set-addbyfixVal').text('最高不得多于');
			}
		});

		// 调价模式 -原基础上调价
		$(document).on('click', '.addpricewithratio', function() {
			var $this = $(this);
			var this_p = $this.parents('.k_box');
			this_p.find('[name=addbyfix]').attr('checked', false);
			this_p.find('[name^="addbyfixVal"]').val('').attr('disabled', true);
			this_p.find('[name^="setbyfixVal"]').val('');

			this_p.find('[name^="addpricewithratioVal"]').attr('disabled', false);
			this_p.find('[name=addpricewithratioVal]').focus();
			this_p.find('[name=priceModel]').val(2);

			if($this.val() == 1) {
				$('#s-model-value-set-addpricewithratioVal').text('最低不得少于');
			} else {
				$('#s-model-value-set-addpricewithratioVal').text('最高不得多于');
			}
		});

		// 调价模式 -统一出价
		$(document).on('focus', '.setbyfixVal', function() {
			var $this = $(this);
			var this_p = $this.parents('.k_box');
			this_p.find('[name=addbyfix],[name=addpricewithratio]').attr('checked', false);
			this_p.find('[name^="addpricewithratioVal"],[name^="addbyfixVal"]').val('').attr('disabled', true);
			this_p.find('[name=priceModel]').val(3);
		});

		// 匹配模式
		$(document).on('change', '.matchscopeModel', function() {
			var $this = $(this);
			if ($this.is(':checked')) {
				$this.parents('.matchscope').find('input[name=matchscope]').attr('disabled', false);
				$this.parents('.matchscope').find('input[name=matchscope]:first').attr('checked', true);
			} else {
				$this.parents('.matchscope').find('input[name=matchscope]').attr('disabled', true);
				$this.parents('.matchscope').find('input[name=matchscope]').attr('checked', false).attr('disabled', true);
			}
		})

		// 开启/关闭调价模式
		$(document).on('change', '.priceModelStart', function() {
			var $this = $(this);
			if ($this.is(':checked')) {
				$(document).find('.s-model input').attr('disabled', false);
			} else {
				$(document).find('.s-model input').attr('disabled', true);
			}
		});
		
	})(jQuery);
	
</script>